package com.danger.Presenter;

import android.content.Context;

import com.danger.Model.action.UploadPhotoModel;
import com.danger.Model.action.UploadPhotoModelImpl;
import com.danger.Model.listener.OnUploadPhotoListener;
import com.danger.View.UploadPhotoView;

/**
 * Created by danger on 2016/4/4.
 */
public class UploadPhotoPresenterImpl implements UploadPhotoPresenter {

    private Context context;
    private UploadPhotoModel uploadPhotoModel;
    private UploadPhotoView uploadPhotoView;

    public UploadPhotoPresenterImpl(Context context, UploadPhotoView uploadPhotoView) {
        this.context = context;
        this.uploadPhotoView = uploadPhotoView;
        uploadPhotoModel = new UploadPhotoModelImpl(context);
    }

    @Override
    public void upload(String path) {
        uploadPhotoView.showDialog();
        uploadPhotoModel.upload(path, new OnUploadPhotoListener() {
            @Override
            public void onSuccess(String url) {
                uploadPhotoView.hideDialog();
                uploadPhotoView.showSuccess("上传成功", url);
                uploadPhotoView.toNext();
            }

            @Override
            public void onError(String s) {
                uploadPhotoView.hideDialog();
                uploadPhotoView.showError(s);
            }
        });
    }
}
